namespace EntityFrameworkSample.Data.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class initial : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Courses",
                c => new
                    {
                        CourseId = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        Code = c.String(),
                    })
                .PrimaryKey(t => t.CourseId);
            
            CreateTable(
                "dbo.Semesters",
                c => new
                    {
                        SemesterId = c.Int(nullable: false, identity: true),
                        StartDate = c.DateTime(nullable: false),
                        EndDate = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.SemesterId);
            
            CreateTable(
                "dbo.SemesterStudentCourses",
                c => new
                    {
                        SemesterStudentCourseId = c.Int(nullable: false, identity: true),
                        SemesterId = c.Int(nullable: false),
                        StudentId = c.Int(nullable: false),
                        CourseId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.SemesterStudentCourseId)
                .ForeignKey("dbo.Courses", t => t.CourseId, cascadeDelete: true)
                .ForeignKey("dbo.Semesters", t => t.SemesterId, cascadeDelete: true)
                .ForeignKey("dbo.Students", t => t.StudentId, cascadeDelete: true)
                .Index(t => t.SemesterId)
                .Index(t => t.StudentId)
                .Index(t => t.CourseId);
            
            CreateTable(
                "dbo.Students",
                c => new
                    {
                        StudentId = c.Int(nullable: false, identity: true),
                        FirstName = c.String(),
                        LastName = c.String(),
                    })
                .PrimaryKey(t => t.StudentId);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.SemesterStudentCourses", "StudentId", "dbo.Students");
            DropForeignKey("dbo.SemesterStudentCourses", "SemesterId", "dbo.Semesters");
            DropForeignKey("dbo.SemesterStudentCourses", "CourseId", "dbo.Courses");
            DropIndex("dbo.SemesterStudentCourses", new[] { "CourseId" });
            DropIndex("dbo.SemesterStudentCourses", new[] { "StudentId" });
            DropIndex("dbo.SemesterStudentCourses", new[] { "SemesterId" });
            DropTable("dbo.Students");
            DropTable("dbo.SemesterStudentCourses");
            DropTable("dbo.Semesters");
            DropTable("dbo.Courses");
        }
    }
}
